<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
   <% String path=request.getContextPath(); 
   String basePath=request.getScheme()
    + "://" + request.getServerName() + ":" + request.getServerPort() + path
    + "/"; 

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>出单用户维护</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">

<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>

<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>

<style type="text/css">
#saveAppTable tr td{border-bottom:1px solid #A4BDE3;}
</style>
<script>
$(document).ready(function() {
	$("#userTypeCode_input").change(function(){
		var userTypeValue = $("#userTypeCode_input").val();
		if("1"==userTypeValue){
			$("#searchChannelInfoDIV").css("display","");
			$("#searchAgencyInfoDIV").css("display","none");
			$("#agencyCode_input").val('');
		}else if("2"==userTypeValue){
			$("#searchAgencyInfoDIV").css("display","");
			$("#searchChannelInfoDIV").css("display","none");
			$("#channelCode_input").val('');
		}
		else{
			$("#searchChannelInfoDIV").css("display","none");
			$("#searchAgencyInfoDIV").css("display","none");
			$("#channelCode_input").val('');
			$("#agencyCode_input").val('');
		}
	});
	isReadyIframe();
	queryFacadeUser(1);
});

function isReadyIframe(){
	var iframe = $(window.parent.document).find("#iframe").length;
	if(iframe==0){
		window.location.href="<%=path%>/index.jsp";
	}
}
var finalUserTypeCode="";
//重置
function resetSearch(){
	$('#userCode_input').val("");
	$('#userName_input').val("");
	$('#userTypeCode_input').val("");
	$('#channelCode_input').val("");
	$('#agencyCode_input').val("");
	$("#searchChannelInfoDIV").css("display","none");
	$("#searchAgencyInfoDIV").css("display","none");
}
/**
 * 页面初始化查询显示所有用户列表
 */
function queryFacadeUser(pageIndex){
	var uname = $('#userName_input').val();
	var ucode = $('#userCode_input').val();
	var userTypeCode = $('#userTypeCode_input').val();
	var fKSubChannelCode = $('#channelCode_input').val();
	var agencyCode = $('#agencyCode_input').val();
	$.openLoading();
	$.ajax({
		url : "<%=path%>/facadeManager/initFacadeUsers",
		type : 'POST',
		async : true,
		data:{"pageIndex":pageIndex,"userName":uname,"userCode":ucode,
			"userTypeCode":userTypeCode,"fKSubChannelCode":fKSubChannelCode,"agencyCode":agencyCode},
		dataType:'json',
		success:function(userPage){
			$.closeLoading();
			if($.validate(userPage))return;
			//业务处理
				if(null != userPage){
					//var buttonStr = "<a href='javascript:void(0)' onClick='editUser(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='warn(this)'>删除</a>&nbsp;<a href='javascript:void(0)' onClick='warnResetPwd(this)'>重置密码</a>";
					var fieldNames = "userid@TDH,user_code,user_name,email,telephone,status,userTypeCode@TDH,userTypeDscp,fKSubChannelCode@TDH,fKSubChannelDesc,operate_type,FK_CHANNEL_CODE@TDH";
					var tableContent = creatTable(fieldNames,userPage,null);
					var tableObj = $("#userTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage(pageIndex,6,userPage.maxPage,"21");
					var pageDIV = $("#userPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
				}
		}
	});
}


//获取选中的合作伙伴
var channelCodeStr;
function chooseChannels(e, treeId, treeNode) {
var sNodes = deptTreeObj.getCheckedNodes();
if(sNodes.length>0){
	for(var i=0;i<sNodes.length;i++){
		channelCodeStr+= sNodes[i].id+',';
	}
	}
}	


//var curUserid = "";
//打开合作伙伴树形列表
<%-- function openChannelTree(obj){
	var delTr = $(obj).parent('td').parent('tr')[0];
	curUserid = delTr.childNodes[0].innerHTML;
		var setting = {
				data: {
					simpleData: {
						enable: true
					}
				},
				view: {
					dblClickExpand: true
				},
				callback: {
					onClick: openDeptTree
				},
				check: {
					enable: true,
					chkStyle: "checkbox",
					chkboxType: { "Y": "s", "N": "s" }
				}
			};
		$.openLoading();
		$.ajax({
			url: "<%=path%>/facadeManager/initChannelTree",
			type: "post",
			dataType: "json",
			async:true,
			cache:false,
			success: function(data) {
				$.closeLoading();
				if($.validate(data))return;
				//业务处理
					deptTreeObj = $.fn.zTree.init($("#deptTreeDemo"), setting, data);
					$('#pDeptDiv').OpenDiv();
 
					$.ajax({
						url: "<%=path%>/facadeManager/getChannelsOfCurUser",
						type: "post",
						dataType: "json",
						data:{"userId":curUserid},
						async:true,
						success: function(data) {
							if($.validate(data))return;
							//业务处理
								if(data!=null){
									$.each(data,function(i,item){
										deptTreeObj.checkNode(deptTreeObj.getNodeByParam("id", item.channelCode, null), true, true);
									})
								}else{
									$.message("error", "合作伙伴加载失败");
								}
						$('#pDeptDiv').OpenDiv();
						}
					});
 					
			}
		});
} --%>
//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
function bindradio(){
	$("input[name='agencyradio']").click(function(){
		$("input[name='agencyradio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
	$("input[name='subChannelradio']").click(function(){
		$("input[name='subChannelradio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
}
var searchChannelInfoFlag='';
<%------------------------------------------- 合作伙伴子机构开始----------------------------------------------%>
function openSubChannelInfoDiv(pageIndex,obj){
	searchChannelInfoFlag = obj;
	$("#"+obj.id).blur();
	querysubChannelInfo(pageIndex);
}
function querysubChannelInfo(pageIndex){
	$("#BigDiv2").remove();
	var subChannelCode = $("#subChannelCodeInput").val();
	var subChannelName = $("#subChannelNameInput").val();
	var size = 8;
	$.openLoading();
	$.ajax({
		url :"<%=path%>/facadeManager/initChannelTree?"+new Date().getTime(),
		type : 'POST',
		async : true,
		data:{
			size:size,
			pageIndex:pageIndex,
			subChannelCode:subChannelCode,
			subChannelName:subChannelName
		},
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;
					var radioObj ="<input class='input_fxk' name='subChannelradio' type='radio' value=''>";
					var fieldNames = "SUB_CHANNEL_CODE,SUB_CHANNEL_NAME,PARENT_CHANNEL_CODE@TDH,CHANNEL_NAME,IS_HQ_USER_TYPE@TDH,IS_HQ_USER_TYPE?[{'Y':'总对总代理'};{'N':'合作伙伴'}],CHANNELCODE@TDH";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#subChannelInfoTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					var strPage = creatChannelPage2(pageIndex,6,partnerPage.maxPage,"39");
					var pageDIV = $("#subChannelInfoPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$('#subChannelInfoDiv').OpenDiv2();
					
					bindradio();
			}
	});
}
//
function chooseSubChannelInfo(){
	var selectedProd= $("input[name='subChannelradio']:checked");
	if(selectedProd.length==0){
		$.message("error", "请选择上级合作伙伴机构");
		return;
	}
	var subChannelCode = selectedProd.parent().parent().children(" td:eq(1)").html();
	var subChannelName = selectedProd.parent().parent().children(" td:eq(2)").html();
	//获取合作伙伴
	var channelCode=selectedProd.parent().parent().children(" td:eq(7)").html();
	if('search'==searchChannelInfoFlag){
		$("#channelCode_input").val(subChannelCode);
	}else{
		finalUserTypeCode =  selectedProd.parent().parent().children(" td:eq(5)").html();
		if('N' == finalUserTypeCode){
			finalUserTypeCode ='1';
		}else if('Y' == finalUserTypeCode){
			finalUserTypeCode ='4';
		}
		$("#channelCode_div").val(subChannelCode);
		$("#channelName_div").val(subChannelName);
		$("#userChannel").val(channelCode);
		
	}
	$("#subChannelInfoDiv").CloseDiv2();
	$("#subChannelCodeInput").val('');
	$("#subChannelNameInput").val('');
	searchChannelInfoFlag ='';
	$("#subChannelInfoDiv").CloseDiv2();
}
//
function closeSubChannelInfoDiv(){
	$("#subChannelInfoDiv").CloseDiv2();
	$("#subChannelCodeInput").val('');
	$("#subChannelNameInput").val('');
	searchChannelInfoFlag ='';
	finalUserTypeCode = "";
}
<%------------------------------------------- 合作伙伴子机构 结束----------------------------------------------%>
<%--树形结构完整版  //加载channelTree
function loadChannelTree(obj){
	searchChannelInfoFlag = obj;
	$.openLoading();
	$.ajax({
		url : "<%=path%>/facadeManager/initChannelTree?"+new Date().getTime(),
		type : 'POST',
		async : true,
		dataType:'json',
		success:function(data){
			var setting = {
					check: {
						enable: true,
						chkStyle: "radio",
						radioType: "all"
					},
					data: {
						simpleData: {
							enable: true
						}
					}
				};

				$.fn.zTree.init($("#channelTree"), setting, data);
				
				$("#channelTreeDiv").OpenDiv2();
		},
		complete:function (){
			$.closeLoading();
		}
	});
}

//隐藏 channelTree层
function closeChannelTreeDiv(){
	$("#channelTreeDiv").CloseDiv2();
	searchChannelInfoFlag='';
}
//点击“确定”(选择所属channel)
function chooseChannel(){
	var channelTree = $.fn.zTree.getZTreeObj("channelTree");
	if(channelTree.getCheckedNodes(true).length==0){
		$.message("error", "请选择合作伙伴机构");
		return;
	}
	var channels = channelTree.getCheckedNodes(true);
	if('search'==searchChannelInfoFlag){
		$("#channelCode_input").val(channels[0].id);
	}else{
		$("#channelCode_div").val(channels[0].id);
		$("#channelName_div").val(channels[0].name);
	}
 	$("#channelTreeDiv").CloseDiv2();
}
--%>
<%-- //保存 合作伙伴配置
function saveChannel(){
	channelCodeStr='';
	chooseChannels();
	if(channelCodeStr==''){
		$.message("error","请至少选择一个合作伙伴");
		return;
	}
	
	$.openLoading();
	$.ajax({
		url: "<%=path%>/facadeManager/bindChannelToUser",
		type: "post",
		dataType: "json",
		data:{"channelCodeStr":channelCodeStr,"userId":curUserid},
		async:true,
		success: function(data) {
			$.closeLoading();
			if($.validate(data))return;
			closeCurrentDIV('pDeptDiv');
		}
	});
} --%>



function openDeptTree(event, treeId, treeNode){
	if(treeNode.isParent){
		var isOpen = treeNode.open;
		deptTreeObj.expandNode(treeNode,!isOpen);
	}
}




//加载合作伙伴
function queryPartner(param){
	$("#BigDiv2").remove();
	$.openLoading();
	$.ajax({
		url : "insure/loadChannelInfo",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;
					var radioObj ="<input class='input_fxk' name='partnerradio' type='radio' value=''>";
					var fieldNames = "channelCode@TDH,channelCode,channelName";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#TradPartnerTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage2(param.pageIndex,6,partnerPage.maxPage,"16");
					var pageDIV = $("#TradPartnerPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$('#tradPartnerDiv').OpenDiv2();
					
					bindradio();
			}
	});
}  

//点击“确定”按钮，选择合作伙伴
function choosePartner(){
	var selectedPartner = $("input[name='partnerradio']:checked");
	if(selectedPartner.length==0){
		$.message("error", "请选择一个合作伙伴");
		return;
	}
	var pno = selectedPartner.parent().parent().children(" td:eq(1)").html();
	var pname = selectedPartner.parent().parent().children(" td:eq(3)").html();
	$('#channel').val(pno);
	closeCurrentDIV('tradPartnerDiv');
}





var userid;  //该id为主页面用户点击“编辑”、“删除”、“重置密码“、“解锁“等超链接时获取的所在行的用户ID

function warn(userObj){
	$.dialog({
		type: "warn",
		content: "您确定要删除该用户吗？",
		onOk: function() {
			delUser(userObj);
		}
	});
}


//删除用户
function delUser(userObj)
{
	var delTr = $(userObj).parent('td').parent('tr')[0];
	userid = delTr.childNodes[0].innerHTML;
	var userTypeCode = delTr.childNodes[6].innerHTML;
	var fKSubChannelCode =  delTr.childNodes[8].innerHTML;
	var agencyCode =  delTr.childNodes[8].innerHTML;
	var channelCode =  delTr.childNodes[11].innerHTML;
	$.ajax({
		url : "<%=path%>/facadeManager/delUser",
		type : 'POST',
		async : true,
		data:{"userid":userid,"fKSubChannelCode":fKSubChannelCode,"userTypeCode":userTypeCode,"agencyCode":agencyCode,channelCode:channelCode},
		dataType:'json',
		success:function(data){
			if($.validate(data))return;
			queryFacadeUser(1);
		}
	});
}

//”编辑“ 用户信息

function editUser(userObj){
	var delTr = $(userObj).parent('td').parent('tr')[0];
	userid = delTr.childNodes[0].innerHTML;
	$('#stustr').css('display','');
	//弹出层 展示用户信息
$.ajax({
		url : "<%=path%>/facadeManager/queryUserById",
		type : 'POST',
		async : true,
		data:{"userid":userid},
		dataType:'json',
		success:function(data){
			if($.validate(data))return;
			$('#username').val(data.userName);
			$('#channel').val(data.fkChannelCode);
			$('#email').val(data.email);
			$('#phone').val(data.telephone);
			$('#status').val(data.status);
			if('1'==data.userTypeCode || '4' == data.userTypeCode){
				finalUserTypeCode = data.userTypeCode;
				$("input[type=radio][name=userTypeCode][value=1]").attr("checked",true);
				$('#channelName_div').val(data.fKSubChannelDesc);
				$('#channelCode_div').val(data.fKSubChannelCode);
				$('#userChannel').val(data.fkChannelCode);
		 		$("#channelSubInfo").css('display','');
		 		$('#agencyInfo').css('display','none');
 			}
			else{
				$("input[type=radio][name=userTypeCode][value=2]").attr("checked",true);
				$('#agencyCode').val(data.fKSubChannelCode);
				$("#channelSubInfo").css('display','none');
		 		$('#agencyInfo').css('display','');
			}
			$('#unamespan').html(data.userCode);
		}
	});

	cleanErrorMsg('edit');
	$('#nameRed').css('display','none');
	$("#editUserInfoDiv").OpenDiv();
	$('#usercode').css('display','none');
	$("#saveBtn").attr("onclick","").unbind("click").click(function(){  
		saveUser();  
		}) 	
}

//关闭  窗口
function closeCurrentDIV(obj){
	if(obj == 'tradPartnerDiv' ||　obj == 'agencyInfoDiv'){
		$("#"+obj).CloseDiv2();
		$('#channelCode').val('');
		$('#channelName').val('');
		$('#agencyCode_div2').val('');
		searchAgencyFlag='';
	}else{
		$("#"+obj).CloseDiv();
		$("input[name='subChannel']").val("");
		if(obj == 'editUserInfoDiv'){
			$("input[type=radio][name=userTypeCode][value=1]").attr("checked",true);
			$('#agencyInfo').css('display','none');
	 		$("#channelSubInfo").css('display','');
		}
	}
}

//保存修改用户信息
function saveUser(){
	var username = $('#username').val();
	if(username.length==0){
		$.message("error","请输入姓名");
		return;
	}
	var usercode = $('#unamespan').html();
	var email = $('#email').val();
	var telephone = $('#phone').val();
	var reg = new RegExp("^\\d{7,20}$");
	if(telephone.length==0){
		$.message("error","请输入用户电话");
		return;
	}else{
		if(!(reg.test(telephone))){
			$.message("error","用户电话：只能录入不小于七位数的数字");
			return;
		}
	}
	var status = $('#status').val();
	var channel = $('#channel').val();
	var userTypeCode = $('input:radio[name="userTypeCode"]:checked').val();
	if('1'== userTypeCode){
		var channelCode_div = $.trim($("#channelCode_div").val());
		var channelCode = $.trim($("#userChannel").val());
		if(channelCode_div.length == 0){
			$.message("error", "请选择所属机构");
			return;
		}
		$('#agencyCode').val('');
		userTypeCode = finalUserTypeCode;
	}else if('2'==userTypeCode){
		var agencyCode = $.trim($("#agencyCode").val());
		if(agencyCode.length == 0){
			$.message("error", "请选择中介公司");
			return;
		}
		$('#channelCode_div').val('');
	}else{
		$.message("error", "用户类型选择错误，请检查");
		return;
	}
	//弹出层 编辑用户信息
	$.ajax({
		url : "<%=path%>/facadeManager/editUser",
		type : 'POST',
		async : true,
		data:{"userid":userid,"username":username,"email":email,"telephone":telephone,
			"status":status,"channel":channel,"fKSubChannelCode":channelCode_div,"userTypeCode":userTypeCode,"agencyCode":agencyCode,"channelCode":channelCode,"fkChannelCode":channelCode},
		dataType:'json',
		success:function(data){
			if($.validate(data))return;
			closeCurrentDIV("editUserInfoDiv");
			finalUserTypeCode="";
			queryFacadeUser(1);
		}
	});
}



//清理添加用户窗口错误信息
function cleanErrorMsg(obj){
	if(obj="edit"){
		$('#errorCode').html('');
		$('#errorPhone').html('');
		$('#errorEmail').html('');
	}
	if(obj="add"){
		$('#username').val('');
		$('#usercode').val('');
		$('#channel').val('');
		$('#email').val('');
		$('#phone').val('');
		$('#errorCode').html('');
		$('#errorName').html('');
		$('#errorChannel').html('');
		$('#errorPhone').html('');
		$('#errorEmail').html('');
	}
}
//打开添加用户窗口
function openAddUserDIV(){
	$('#unamespan').html('');
	cleanErrorMsg('add');	
	$("#editUserInfoDiv").OpenDiv();
	$('#stustr').css('display','none');
	$('#agencyInfo').css('display','none');
	$('.red').css('display','inline');
	$('#usercode').css('display','inline');
	$("#saveBtn").attr("onclick","").unbind("click").click(function(){  
		addUser();  
		}) 	
}
//添加用户
function addUser(){
	var username = $.trim($('#username').val());
	var usercode = $.trim($('#usercode').val());
	var email = $('#email').val();
	var telephone = $('#phone').val();
	var channelCode_div = $.trim($("#channelCode_div").val());

	if(usercode.length==0){
		$.message("error","请输入用户名");
		return;
	}
	if(username.length==0){
		$.message("error","请输入姓名");
		return;
	}
	var reg = new RegExp("^\\d{7,20}$");
	if(telephone.length==0){
		$.message("error","请输入用户电话");
		return;
	}else{
		if(!(reg.test(telephone))){
			$.message("error","用户电话：只能录入不小于七位数的数字");
			return;
		}
	}
	var userTypeCode = $('input:radio[name="userTypeCode"]:checked').val();
	if('1'== userTypeCode){
		var channelCode_div = $.trim($("#channelCode_div").val());
		if(channelCode_div.length == 0){
			$.message("error", "请选择所属机构");
			return;
		}
		var channelCode = $.trim($("#userChannel").val());
		$('#agencyCode').val('');
		userTypeCode = finalUserTypeCode;
	}else if('2'==userTypeCode){
		var agencyCode = $.trim($("#agencyCode").val());
		if(agencyCode.length == 0){
			$.message("error", "请选择中介公司");
			return;
		}
		$('#channelCode_div').val('');
	}else{
		$.message("error", "用户类型选择错误，请检查");
		return;
	}
	$.openLoading();
	$.ajax({
		url : "<%=path%>/facadeManager/addUser",
		type : 'POST',
		async : true,
		data:{"username":username,"usercode":usercode,"email":email,"telephone":telephone,"fKSubChannelCode":channelCode_div,"fkChannelCode":channelCode,
			"userTypeCode":userTypeCode,"agencyCode":agencyCode},
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if(data!=null && data.result=="error"){
/* 				if(data.message=="notexist"){
					$.message("error","UM系统中不存在该用户名，请在UM系统中添加该用户后进行操作");
				}else{
				}
 */					
 			$.message("error",data.message);
			}else{
				if(data != null){
					if("fail"==data.result){
			    		$.message("error", "系统错误,请联系管理员");
			    		return;
			    	}
					if("error"==data.result&&""!=data.message){
			    		$.message("error", data.message);
			    		return;
			    	}
					if("success"==data.result&&""!=data.message){
						$.dialog({
							type: "success",
							width:340,
							content: data.message,
							cancel:null
						});
			    	}
				}else{
					return;
				}
				closeCurrentDIV("editUserInfoDiv");
				queryFacadeUser(1);
			}
		}
	});
}


function reductionBorder(obj){
	var code = $.trim($('#usercode').val());
	if(obj=="usercode"){
		if(code.length>0){
				$.ajax({
					url : "<%=path%>/facadeManager/queryUsercodeIsExists",
					type : 'POST',
					async : true,
					data:{"usercode":code},
					dataType:'json',
					success:function(data){
						if(data!=null && data.result=="error"){
/* 							if(data.message=="notexist"){
								$.message("error","UM系统中不存在该用户名，请在UM系统中添加该用户后进行操作");
							}else{
							}
 */								$.message("error",data.message);
						}
					}
				});
			}
		}
}



//重置密码弹出 提示框
function warnResetPwd(obj){
	var mTr = $(obj).parent('td').parent('tr')[0];
	var uname = mTr.childNodes[2].innerHTML;
	$.dialog({
		type: "warn",
		content: "确认要给用户 "+uname+" 重置密码吗？",
		onOk: function() {
			resetPassword(obj);
		}
	});
}
//重置密码
function resetPassword(obj){
	var mTr = $(obj).parent('td').parent('tr')[0];
	var uname = mTr.childNodes[2].innerHTML;
	userid = mTr.childNodes[0].innerHTML;
	$.ajax({
		url : "<%=path%>/facadeManager/resetPwd",
		type : 'POST',
		async : true,
		data:{"userid":userid},
		dataType:'json',
		success:function(data){
			if(data != null){
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    		return;
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    		return;
		    	}
				if("success"==data.result&&""!=data.message){
					$.dialog({
						type: "success",
						width:340,
						content: data.message,
						cancel:null
					});
		    	}
			}else{
				return;
			}
		}
	});
}

//用户解锁
function unlock(obj){
	var mTr = $(obj).parent('td').parent('tr')[0];
	var uname = mTr.childNodes[2].innerHTML;
	$.dialog({
		type: "warn",
		content: "确认要给用户 "+uname+" 解锁吗？",
		onOk: function() {
			unlockUser(obj);
		}
	});
}
//解锁
function unlockUser(obj){
	var mTr = $(obj).parent('td').parent('tr')[0];
	var uname = mTr.childNodes[2].innerHTML;
	userid = mTr.childNodes[0].innerHTML;
	$.ajax({
		url : "<%=path%>/facadeManager/unlock",
		type : 'POST',
		async : true,
		data:{"userid":userid},
		dataType:'json',
		success:function(data){
			if(data != null){
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    		return;
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    		return;
		    	}
				if("success"==data.result&&""!=data.message){
					$.message("success", data.message);
		    		return;
		    	}
			}else{
				return;
			}
		}
	});
}

// agency begin
//打开中介窗口
var searchAgencyFlag="";
function openAgencyInfoDiv(pageIndex,obj){
	searchAgencyFlag = obj;
	$('#agencyCode_div2').val('');
	$('#agencyName_div2').val('');
	$("#"+obj.id).blur();
	queryAgencyInfo(pageIndex);
}
//点击“查询”
function queryAgencyInfo(pageIndex){
	$("#BigDiv2").remove();
	var agencyCode = $.trim($("#agencyCode_div2").val());
	var agencyName = $.trim($("#agencyName_div2").val());
	$.openLoading();
	//按照条件执行查询操作
	$.ajax({
		url : "<%=path%>/agencyManage/queryByCriteria?"+new Date().getTime(),
		type : 'POST',
		async : true,
		dataType:'json',
		data:{
			agencyCode:agencyCode,
			agencyName:agencyName,
			pageIndex:pageIndex
		},
		success:function(agencyInfoPage){
			$.closeLoading();
			
			if($.validate(agencyInfoPage))  return;
			
			if(null != agencyInfoPage){
				var radioObj ="<input class='input_fxk' name='agencyradio' type='radio' value=''>";
				var fieldNames = "AGENCY_CODE,AGENCY_NAME";
				var tableContent = creatTable1(fieldNames,agencyInfoPage,radioObj);
				var tableObj = $("#agencyInfoTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage2(pageIndex,6,agencyInfoPage.maxPage,"24");
				var pageDIV = $("#agencyInfoPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				$("#agencyInfoDiv").OpenDiv2();
				bindradio();
			}
		}
	});
}

//点击“确定” ，选择 产品

function chooseAgencyInfo(){
	var selectedProd= $("input[name='agencyradio']:checked");
	if(selectedProd.length==0){
		$.message("error", "请选择一个中介公司");
		return;
	}
	
	var agencyCode = selectedProd.parent().parent().children(" td:eq(1)").html();//产品代码
	if('search'== searchAgencyFlag){
		$('#agencyCode_input').val(agencyCode);
	}
	else{
		$('#agencyCode').val(agencyCode);
	}
 	closeCurrentDIV('agencyInfoDiv');
}

function userTypeChange(obj){
	var value = $('input:radio[name="userTypeCode"]:checked').val();
 	if("1"==value){
 		$('#agencyInfo').css('display','none');
 		$("#channelSubInfo").css('display','');
 	}else{
 		$("#channelSubInfo").css('display','none');
 		$("#agencyInfo").css('display','');
 	}
}

</script>
</head>

<body>
	<div class="current">
           <table class="current_table_1">
              <tbody><tr class="f2">
                <td><img src="./images/current_1.jpg"></td>
                  <td class="current_table_1_td">
                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                  <span style=" color:#136bab; ">界面出单管理
                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>出单用户维护
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody></table>
      </div>

	<%--显示user的表格 --%>
	<table border="1" class="table_02" style="height:150px">
  		<tr height="50px">
  			<td colspan="2" align="center">
  				用户名：&nbsp;<input id="userCode_input" class="input_text"/>&nbsp;
				姓名：&nbsp;<input id="userName_input" class="input_text"/>&nbsp;
				用户类型 ：&nbsp;<select id="userTypeCode_input"><option value="">---请选择---</option><option value="1">合作伙伴用户</option><option value="2">中介公司用户</option><option value="3">个人代理用户</option></select>&nbsp;
				<span id = "searchChannelInfoDIV" style="display:none;">
					合作伙伴代码 ：&nbsp;<input readonly="readonly" id="channelCode_input" class="input_text" style="background: #ccc;width:120px;"/>
					<input type="button"  class="input_button_2" style="width: 60px;" id="searchChannelCodeBtn" value="请选择" onClick="openSubChannelInfoDiv(1,'search')"/>&nbsp;&nbsp;
				</span>
				<span id = "searchAgencyInfoDIV" style="display:none;">
					中介公司代码 ：&nbsp;<input readonly="readonly" id="agencyCode_input" class="input_text" style="background: #ccc;width:120px;"/>
					<input type="button"  class="input_button_2" style="width: 60px;" id="searchAgencyCodeBtn" value="请选择" onClick="openAgencyInfoDiv(1,'search')"/>&nbsp;&nbsp;
				</span>
				<input type="button" id="queryFacadeUserBtn" class="input_button_1" value="查询" onclick="queryFacadeUser(1)"/>&nbsp;
				<input type="button" id="resetSearchBtn" class="input_button_1"  value="重置" onclick="resetSearch()"/>&nbsp;
				<input type="button" id="addUserBtn" class="input_button_1"  value="新增" onclick="openAddUserDIV()"/>
			</td>
  		</tr>
  		<tr>
  			<td valign="top">
	  			<div id="userDIV" style="width:98%;margin:5px">
			  		<table class="table_02" id="userTable">
			  		<thead>
		              <tr>
		                  <th style="width:10%">用户名</th>
		                  <th style="width:16%">姓名</th>
		                  <th style="width:14%">邮件地址</th>
		                  <th style="width:10%">用户电话</th>
		                  <th style="width:6%">状态</th>
		                  <th style="width:10%">用户类型</th>
		                  <th style="width:20%">所属合作伙伴机构/中介公司</th>
		                  <th style="width:14%">操作</th>
		              </tr>
		              </thead>
		              <tbody>
					  </tbody>
		            </table>
						<div id="userPageDIV"  class="page" >
	  				 </div>
	  			</div>
  			</td>
  		</tr>
  	</table>
	
	<!--   	编辑用户信息 DIV 默认隐藏-->
  		<div id="editUserInfoDiv" style="display:none;width:600px;height:260px;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('editUserInfoDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="saveAppTable" style="height:68%;width: 95%" align="center" >
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">用户名：</td>
				<td style="text-align:left;" width="60%" colspan="2">&nbsp;&nbsp;<span id="unamespan"></span><input type="text" id="usercode" class="input_text" onchange="reductionBorder('usercode')" >
				<span class="red" id="nameRed">*</span>
				<span id="errorCode"></span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">姓名：</td>
				<td style="text-align:left;" width="60%" colspan="2">&nbsp;&nbsp;<input type="text" id="username" class="input_text"  onblur="reductionBorder('username')">
				<span class="red">*</span>
				<span id="errorName"></span>
				</td>
			</tr>
<!-- 			<tr>
				<td style="text-align:right;border-right:0px;" width="30%">所属合作伙伴：</td>
				<td style="text-align:left;" width="70%" colspan="2">&nbsp;&nbsp;<input type="text" id="channel" class="input_text"  readonly="readonly" style=" background-color: #ccc;">
				<span class="red">*</span>
				<input type="button" id="addubtn" class="input_button_1"  value="选择" onclick="openChannelDiv('tradPartnerDiv',1,this)"/>
				<span id="errorChannel"></span>
				</td>
			</tr>
 -->
 			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">用户电话：</td>
				<td style="text-align:left;" width="60%" colspan="2">&nbsp;&nbsp;<input type="text" id="phone" class="input_text" maxlength="20" onblur="reductionBorder('phone')">
				<span class="red">*</span>
				<span id="errorPhone"></span>
				</td>
			</tr>
 			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">邮件地址：</td>
				<td style="text-align:left;" width="60%" colspan="2">&nbsp;&nbsp;<input type="text" id="email" class="input_text"  onblur="reductionBorder('email')"></td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">用户类型：</td>
				<td style="text-align:left;" width="60%" colspan="2">&nbsp;&nbsp;
				<input type="radio" id="userTypeCode" name = "userTypeCode" value="1" checked="checked" onclick="userTypeChange(this)"/>合作伙伴用户
				<input type="radio" id="userTypeCode" name = "userTypeCode" value="2" onclick="userTypeChange(this)"/>中介公司用户&nbsp;<span class="red">*</span>
				</td>
			</tr>
			<tr id="stustr">
				<td style="text-align:right;border-right:0px;" width="40%">状态：</td>
				<td style="text-align:left;" width="60%" colspan="2">
				    &nbsp;&nbsp;<select id="status" style="width:130px;">
						<option value="1">有效</option>
						<option value="2">无效</option>
					</select>
				</td>
			</tr>
			<tr id="channelSubInfo">
				<td style="text-align:right;border-right:0px;" width="40%">
					所属合作伙伴机构：
				</td>
				<td style="text-align:left;" width="60%" colspan="2">&nbsp;
					<input readonly="readonly" id="channelName_div" name="subChannel" class="input_text" style="background: #ccc;width: 65%"/><span class="red">*</span>
					<input type="button"  class="input_button_2" id="searchProdBtn" value="请选择" onClick="openSubChannelInfoDiv(1,this)"/>
					<input id="channelCode_div" name="subChannel" type="hidden" />
					<input id="userChannel" name="userChannel" type="hidden" />
 				</td>
			</tr>
			<tr id="agencyInfo">
				<td style="text-align:right;border-right:0px;" width="40%">所属中介公司：</td>
				<td style="text-align:left;" width="60%" colspan="2">&nbsp;
					<input name="subChannel" id="agencyCode" type="text" readonly="readonly" style=" background-color: #ccc;width:130px;" class="input_text"><span class="red">*</span>&nbsp;<input type="button"  class="input_button_2" id="searchProdBtn" value="请选择" onClick="openAgencyInfoDiv(1,this)"/>					
 				</td>
			</tr>
		</table>
		<div style="height:30px;width: 95%" align="center">
			<input type="button" id="saveBtn" value="保存" onclick="saveUser()" class="input_button_1"/>&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" onclick="closeCurrentDIV('editUserInfoDiv')" class="input_button_1"/>
		</div>
	</div>
	
		<!--   	选择 合作伙伴 div-->
  		<div id="tradPartnerDiv" style="display:none;width:90%;text-align: center;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('tradPartnerDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">合作伙伴代码：<input name="txt3"  id="channelCode"  type="text" class="input_text" value="" >
								&nbsp;&nbsp;合作伙伴名称：<input name="txt3" id="channelName"  type="text" class="input_text" value="">
								&nbsp;&nbsp;<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradPartners(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="TradPartnerTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="TradPartnerPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" id="saveRoleBtn" value="确定" onclick="choosePartner()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeCurrentDIV('tradPartnerDiv')" class="input_button_3"/>
		</div>
	</div>	
	<%--合作伙伴机构包括子机构支持分页 --%>
	<div id="subChannelInfoDiv"  style="display:none;width:80%">
		<div class="table_title_div">
			<table class="table_title" style='width:100%;height:20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeSubChannelInfoDiv()"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" align="center" >
			<tbody>
				<tr>
					<td>
						<!-- 筛选条件层 -->
						<table class="search_table">
							<tr>
								<td style="text-align:center">
									合作伙伴子机构代码：<input id="subChannelCodeInput" class="input_text" value="">&nbsp;&nbsp;
									合作伙伴子机构名称：<input id="subChannelNameInput" class="input_text" value="">&nbsp;&nbsp;
									<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="querysubChannelInfo(1)"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table id="subChannelInfoTable"  class="content_table_1">
							<thead>
								<tr class="f1">
				                  <th style="width:5%">选择</th>
				                  <th style="width:25%">合作伙伴子机构代码</th>
				                  <th style="width:30%">合作伙伴子机构名称</th>
				                  <th style="width:30%">所属合作伙伴</th>
				                  <th style="width:10%">机构类型</th>
				              	</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
						<div id="subChannelInfoPageDIV" class="page">
						</div>
					</td>
				</tr>
			</tbody>
		</table>
		<div align="center" >
		 <input class="input_button_3" type="button" onclick="chooseSubChannelInfo()" value="确定">&nbsp;&nbsp;
         <input class="input_button_3" type="button" onclick="closeSubChannelInfoDiv()" value="取消">
		</div>
   </div>
	<%--channelTree(选择所属机构层)
    <div id="channelTreeDiv" style="display: none;width:500px;margin-top: -50px" align="center">
    	<div class="table_title_div">
				<table class="table_title" style='width:500px; height: 20px;'>
					<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeChannelTreeDiv()"/></td>
					</tr>
				</table>
		</div>
		
		<div style="height: 300px;width:500px; overflow:auto">
			<ul id="channelTree" class="ztree"></ul>
		</div>
		
		<div style="text-align: center;padding: 5px">
			<input type="button" id="choseChannelBtn" value="确定" onclick="chooseChannel()" class="input_button_1"/>&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" onclick="closeChannelTreeDiv()" class="input_button_1"/>
		</div>
	</div>--%>
	<!--   	产品 DIV 默认隐藏-->
 	<div id="agencyInfoDiv"  style="display:none;width:80%;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
				<table class="table_title" style='width:100%;height:20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('agencyInfoDiv')"/></td>
					</tr>
				</table>
			</div>

		<!-- 修改id 名 -->
		<table class="table_02" id="addtempletTable" align="center" >
			<tbody>
			<tr>
			<td>
				<table class="search_table">
				<tr height="30px" >
						<td style="border:0px;text-align: right;">中介公司代码：</td>
						<td style="border:0px;text-align: left;">
							<input name="txt3"  id="agencyCode_div2"  type="text" class="input_text" value="" style="width:120px;">
						</td>
						<td style="border:0px;text-align: right;">
							中介公司名称：
						</td>
						<td style="border:0px;text-align: left;"><input name="txt3" id="agencyName_div2"  type="text" class="input_text" value="" style="width:120px;">
							&nbsp;&nbsp;<input type="button"  class="input_button_1" id="searchAgencyBtn" value="查询" onClick="queryAgencyInfo(1)"/>
						</td>
				</tr>
			</table>
			</td></tr>
				<tr>
					<td>
						<!-- 修改数据table名 -->
						<table id="agencyInfoTable"  class="content_table_1">
							<thead>
								<tr class="f1">
				                  <th style="width:5%">选择</th>
				                  <th style="width:45%">中介公司代码</th>
				                  <th style="width:50%">中介公司名称</th>
				              	</tr>
							</thead>
							<!-- 修改tobody 默认为空 -->
							<tbody>
							</tbody>
						</table>
						<!-- 修改分页编码id 名  默认为空-->
						<div id="agencyInfoPageDIV" class="page">
						</div>
					</td>
				</tr>
			</tbody>
		</table>
		<div align="center" >
		 <input class="input_button_3" name="" type="button" onclick="chooseAgencyInfo()" value="确定">&nbsp;&nbsp;
         <input class="input_button_3" name="" type="button" onclick="closeCurrentDIV('agencyInfoDiv')" value="取消">
		</div>
   </div>
	
<!-- 	<!-- 	树形 合作伙伴div -->
<!-- <div id="pDeptDiv" style="border:0px solid red;display:none;text-align: center;width:360px;"> -->
<!-- 			<div class="table_title_div" > -->
<!-- 			<table class="table_title" style='width:100%;height: 20px;'> -->
<!-- 						<tr> -->
<!-- 						<td width="10%"></td> -->
<!-- 						<td width="80%" id="interfaceName"></td> -->
<%-- 						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('pDeptDiv')"/></td> --%>
<!-- 						</tr> -->
<!-- 					</table> -->
<!-- 			</div> -->
<!-- 			<div id="tt" style="border:0px solid yellow;height:300px;width:100%;overflow:auto;"> -->
<!-- 			<ul id="deptTreeDemo" class="ztree" ></ul> -->
<!-- 			</div> -->
<!-- 		<div  style='width:100%;'> -->
<!-- 		     <input type="button" id="saveBtn" value="确定" onclick="saveChannel()" class="input_button_3"/>&nbsp;&nbsp;&nbsp; -->
<!-- 		     <input type="button" value="取消" onclick="closeCurrentDIV('pDeptDiv')" class="input_button_3"/> -->
<!-- 		</div> -->
<!-- </div> -->
</body>
</html>